package com.kdpujie.wc;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 单词计数
 */
public class WordCount
{
    public static void main( String[] args )
    {
        // final MultipleParameterTool params = MultipleParameterTool.fromArgs(args);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<String> text = env.fromElements(WordCountText.TEXT);

        DataStream<Tuple2<String, Integer>> counts = text.flatMap(new Tokenizer()).keyBy(value -> value.f0).sum(1);

        System.out.println("Printing result to stdout. Use --output to specify output path.");
        counts.print();
        try {
            env.execute("Streaming WordCount");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}   